package com;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JToggleButton;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.filechooser.FileNameExtensionFilter;

public class GuiAdd extends JFrame implements ItemListener {
    private JTextArea content;
    private JButton jButton1;
    private JButton jButton10;
    private JButton jButton11;
    private JButton jButton12;
    private JButton jButton2;
    private JButton jButton3;
    private JButton jButton4;
    private JButton jButton5;
    private JButton jButton6;
    private JButton jButton7;
    private JButton jButton8;
    private JButton jButton9;
    private JLabel jLabel1;
    private JMenu jMenu1;
    private JMenuBar jMenuBar1;
    private JPanel jPanel1;
    private JScrollPane jScrollPane2;
    private JToggleButton jToggleButton1;
    private JComboBox param1;
    private JComboBox param2;

    public GuiAdd() {
        this.initComponents();
        this.setDefaultCloseOperation(1);
        this.param2.addItemListener(this);
        this.content.setText("package xxxx;\r\noption java_outer_classname = \"xxxx\";\r\n");
    }

    private void initComponents() {
        this.jLabel1 = new JLabel();
        this.jPanel1 = new JPanel();
        this.param1 = new JComboBox();
        this.param2 = new JComboBox();
        this.jToggleButton1 = new JToggleButton();
        this.jButton2 = new JButton();
        this.jButton3 = new JButton();
        this.jButton4 = new JButton();
        this.jButton5 = new JButton();
        this.jButton6 = new JButton();
        this.jButton7 = new JButton();
        this.jButton8 = new JButton();
        this.jButton9 = new JButton();
        this.jButton10 = new JButton();
        this.jScrollPane2 = new JScrollPane();
        this.content = new JTextArea();
        this.jButton1 = new JButton();
        this.jButton11 = new JButton();
        this.jButton12 = new JButton();
        this.jMenuBar1 = new JMenuBar();
        this.jMenu1 = new JMenu();
        this.setDefaultCloseOperation(3);
        this.jPanel1.setBorder(BorderFactory.createTitledBorder("添加message"));
        this.param1.setModel(new DefaultComboBoxModel(new String[]{"repeated", "optional", "required"}));
        this.param1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.param1ActionPerformed(evt);
            }
        });
        this.param2.setModel(new DefaultComboBoxModel(new String[]{"string", "number", "int32"}));
        this.param2.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
                GuiAdd.this.param2ItemStateChanged(evt);
            }
        });
        this.param2.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent evt) {
                GuiAdd.this.param2MouseClicked(evt);
            }
        });
        this.param2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.param2ActionPerformed(evt);
            }
        });
        this.jToggleButton1.setText("@api");
        this.jToggleButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jToggleButton1ActionPerformed(evt);
            }
        });
        this.jButton2.setText("@param");
        this.jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton2ActionPerformed(evt);
            }
        });
        this.jButton3.setText("@return");
        this.jButton3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton3ActionPerformed(evt);
            }
        });
        this.jButton4.setText(";");
        this.jButton4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton4ActionPerformed(evt);
            }
        });
        this.jButton5.setText("message");
        this.jButton5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton5ActionPerformed(evt);
            }
        });
        this.jButton6.setText("/**");
        this.jButton6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton6ActionPerformed(evt);
            }
        });
        this.jButton7.setText("*/");
        this.jButton7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton7ActionPerformed(evt);
            }
        });
        this.jButton8.setText("//");
        this.jButton8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton8ActionPerformed(evt);
            }
        });
        this.jButton9.setText("{");
        this.jButton9.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton9ActionPerformed(evt);
            }
        });
        this.jButton10.setText("}");
        this.jButton10.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton10ActionPerformed(evt);
            }
        });
        GroupLayout jPanel1Layout = new GroupLayout(this.jPanel1);
        this.jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.jButton5).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.jButton6, -1, -1, 32767)).addGroup(jPanel1Layout.createSequentialGroup().addComponent(this.param1, -2, -1, -2).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.param2, -2, 78, -2))).addGap(22, 22, 22).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addComponent(this.jButton7, -1, -1, 32767).addComponent(this.jToggleButton1, -1, 61, 32767)).addPreferredGap(ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addComponent(this.jButton2, -1, -1, 32767).addComponent(this.jButton8, -1, -1, 32767)).addGap(18, 18, 18).addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING, false).addComponent(this.jButton9, -1, -1, 32767).addComponent(this.jButton3, -1, -1, 32767)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING, false).addComponent(this.jButton4, -1, 58, 32767).addComponent(this.jButton10, -1, -1, 32767)).addContainerGap(19, 32767)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addContainerGap(33, 32767).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.param1, -2, -1, -2).addComponent(this.param2, -2, -1, -2).addComponent(this.jToggleButton1).addComponent(this.jButton2).addComponent(this.jButton3).addComponent(this.jButton4)).addGap(18, 18, 18).addGroup(jPanel1Layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jButton5).addComponent(this.jButton6).addComponent(this.jButton7).addComponent(this.jButton8).addComponent(this.jButton9).addComponent(this.jButton10)).addGap(31, 31, 31)));
        this.content.setColumns(20);
        this.content.setRows(5);
        this.content.setText("package xxxx;\noption java_outer_classname = \"xxxx\";");
        this.jScrollPane2.setViewportView(this.content);
        this.jButton1.setText("保存");
        this.jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton1ActionPerformed(evt);
            }
        });
        this.jButton11.setText("打开文件");
        this.jButton11.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton11ActionPerformed(evt);
            }
        });
        this.jButton12.setText("新建");
        this.jButton12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                GuiAdd.this.jButton12ActionPerformed(evt);
            }
        });
        this.jMenuBar1.add(this.jMenu1);
        this.setJMenuBar(this.jMenuBar1);
        GroupLayout layout = new GroupLayout(this.getContentPane());
        this.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(this.jScrollPane2, -2, 393, -2).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(this.jPanel1, -2, -1, -2).addPreferredGap(ComponentPlacement.RELATED).addComponent(this.jLabel1)).addGroup(layout.createSequentialGroup().addComponent(this.jButton12).addGap(10, 10, 10).addComponent(this.jButton1, -2, 89, -2).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(this.jButton11))).addContainerGap(-1, 32767)));
        layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(this.jButton11).addComponent(this.jButton12).addComponent(this.jButton1)).addGap(18, 18, 18).addComponent(this.jScrollPane2, -2, 491, -2).addGap(0, 0, 32767)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(175, 175, 175).addComponent(this.jLabel1)).addGroup(layout.createSequentialGroup().addGap(43, 43, 43).addComponent(this.jPanel1, -2, -1, -2))).addContainerGap(410, 32767)));
        this.pack();
    }

    private void param2ActionPerformed(ActionEvent evt) {
        if (evt.getSource() == this.param2) {
            this.content.setText(this.content.getText() + "  " + this.param2.getSelectedItem() + "");
        }

    }

    private void param1ActionPerformed(ActionEvent evt) {
        if (evt.getSource() == this.param1) {
            this.content.setText(this.content.getText() + this.param1.getSelectedItem() + "");
        }

    }

    private void jToggleButton1ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "@api ");
    }

    private void jButton2ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "\r\n@param ");
    }

    private void jButton3ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "\r\n@return ");
    }

    private void param2ItemStateChanged(ItemEvent evt) {
    }

    public void itemStateChanged(ItemEvent e) {
    }

    private void param2MouseClicked(MouseEvent evt) {
    }

    private void jButton1ActionPerformed(ActionEvent evt) {
        JFileChooser fd = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("*.proto", new String[]{"proto"});
        fd.setFileFilter(filter);
        int result = fd.showSaveDialog((Component) null);
        if (result == 0) {
            File file = new File(fd.getSelectedFile() + ".proto");
            if (file.exists()) {
                int ex = JOptionPane.showConfirmDialog((Component) null, "文件已经存在！是否替换", "提示", 0);
                if (ex == 0) {
                    FileWriter fw = null;

                    try {
                        fw = new FileWriter(file);
                        fw.write(this.content.getText());
                        fw.flush();
                        fw.close();
                    } catch (IOException var14) {
                        Logger.getLogger(GuiAdd.class.getName()).log(Level.SEVERE, (String) null, var14);
                    } finally {
                        ;
                    }
                }
            } else {
                try {
                    file.createNewFile();
                    FileWriter ex1 = new FileWriter(file);
                    ex1.write(this.content.getText());
                    ex1.flush();
                    ex1.close();
                } catch (IOException var13) {
                    Logger.getLogger(GuiAdd.class.getName()).log(Level.SEVERE, (String) null, var13);
                }
            }
        }

    }

    private void jButton4ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + ";");
    }

    private void jButton5ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "\r\nmessage ");
    }

    private void jButton6ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "/**\r\n");
    }

    private void jButton7ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "*/");
    }

    private void jButton8ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "//");
    }

    private void jButton9ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "{");
    }

    private void jButton10ActionPerformed(ActionEvent evt) {
        this.content.setText(this.content.getText() + "}");
    }

    private void jButton11ActionPerformed(ActionEvent evt) {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("(*.proto)", new String[]{"proto"});
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog((Component) null);
        if (returnVal == 0) {
            try {
                FileReader ex = new FileReader(chooser.getSelectedFile());
                char[] by = new char[2];
                String str = "";

                do {
                    str = str + new String(by);
                } while (ex.read(by) != -1);

                this.content.setText(str.trim());
            } catch (IOException var8) {
                ;
            }
        }

    }

    private void jButton12ActionPerformed(ActionEvent evt) {
        this.content.setText("package xxxx;\r\noption java_outer_classname = \"xxxx\";\r\n");
    }

    private OutputStream OutputStream(File file) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    private OutputStream FileOutputStream(File file) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

